﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace FACUI.BasicClass
{
    /// <summary>
    /// 文本
    /// </summary>
    public class WB : Sharp
    {
        public WB(MapData mapData, Point pt, int d, string subType)
            : base(mapData, pt, d)
        {
            base.changeStep = 1;
            base.text = "输入文字";
            base.sharpType = "sbWB";
            base.txtSize = 10;
            base.txtFont = "楷体_GB2312";
            base.txtColor = Color.FromArgb(0x4B,0x81,0xBD);
            this.changeSubType(subType);
        }

        public override void addSize(int r)
        {
            if ((base.sizeDefineWidth > 1) || (r > 0))
            {
                if (r <= 0)
                {
                    if (base.direction == 1)
                    {
                        base.sizeDefineHeight += r;
                    }
                    else
                    {
                        base.sizeDefineWidth += r;
                    }
                }
                else if (base.direction == 1)
                {
                    base.sizeDefineHeight += r;
                }
                else
                {
                    base.sizeDefineWidth += r;
                }
                this.resetSize();
            }
        }

        public override void addSize(int d, Point oldPoint, int oldWidth, int oldHeight, int width, int height)
        {
            switch ((d % 8))
            {
                case 0:
                    base.pointY = oldPoint.Y + height;
                    base.sizeDefineHeight = oldHeight - height;
                    break;

                case 1:
                    base.pointY = oldPoint.Y + height;
                    base.sizeDefineHeight = oldHeight - height;
                    base.sizeDefineWidth = oldWidth + width;
                    break;

                case 2:
                    base.sizeDefineWidth = oldWidth + width;
                    break;

                case 3:
                    base.sizeDefineHeight = oldHeight + height;
                    base.sizeDefineWidth = oldWidth + width;
                    break;

                case 4:
                    base.sizeDefineHeight = oldHeight + height;
                    break;

                case 5:
                    base.pointX = oldPoint.X + width;
                    base.sizeDefineWidth = oldWidth - width;
                    base.sizeDefineHeight = oldHeight + height;
                    break;

                case 6:
                    base.pointX = oldPoint.X + width;
                    base.sizeDefineWidth = oldWidth - width;
                    break;

                case 7:
                    base.pointX = oldPoint.X + width;
                    base.pointY = oldPoint.Y + height;
                    base.sizeDefineWidth = oldWidth - width;
                    base.sizeDefineHeight = oldHeight - height;
                    break;
            }
            if (base.sizeDefineWidth <= 0)
            {
                base.sizeDefineWidth = 1;
            }
            if (base.sizeDefineHeight <= 0)
            {
                base.sizeDefineHeight = 1;
            }
            this.resetSize();
        }

        public override bool changeSubType(string newSubType)
        {
            if (!("0".Equals(newSubType) || "1".Equals(newSubType)))
            {
                return false;
            }
            int num = base.direction % 2;
            if (num == 1)
            {
                base.sizeDefine = new Size(2, 6);
            }
            else
            {
                base.sizeDefine = new Size(6, 2);
            }
            base.subType = newSubType;
            this.resetSize();
            return true;
        }

        public override void checkLine(int[][][] array4checkLine)
        {
        }

        public override void createDigit(string kglDesc)
        {
        }

        public override double distance(Point p, Size r)
        {
            double num = Math.Pow((p.X - (((((double)(this.rectReal.Right + this.rectReal.Left)) / 2.0) * r.Width) / 2.0)) / 2.0, 2.0);
            double num2 = Math.Pow((p.Y - (((((double)(this.rectReal.Bottom + this.rectReal.Top)) / 2.0) * r.Height) / 2.0)) / 2.0, 2.0);
            return (Math.Sqrt(num2 + num2) + 0.001);
        }

        public override void draw(Graphics g, MapSet ct, Pen usePen)
        {
            if (base.inShowArea())
            {
                this.resetSize();
                Rectangle layoutRectangle = new Rectangle(((this.rectReal.Left * ct.gridsize.Width) / 2) + ct.offset.X, ((this.rectReal.Top * ct.gridsize.Height) / 2) + ct.offset.Y, (this.rectReal.Width * ct.gridsize.Width) / 2, (this.rectReal.Height * ct.gridsize.Height) / 2);
                StringFormat format = new StringFormat(StringFormatFlags.NoClip)
                {
                    Alignment = StringAlignment.Center,
                    LineAlignment = StringAlignment.Center
                };
                base.linePen.Color = base.txtColor;
                base.linePen.Width = ct.lineWidth;
                Pen linePen = base.linePen;
                if (base.direction == 0)
                {
                    layoutRectangle.X = layoutRectangle.Left - (ct.gridsize.Width * 4);
                    layoutRectangle.Width += ct.gridsize.Width * 8;
                }
                if (base.direction == 1)
                {
                    layoutRectangle.Y = layoutRectangle.Top - (ct.gridsize.Height * 4);
                    layoutRectangle.Height += ct.gridsize.Height * 8;
                }
                if (!(base.isHideTxt || (((int)(base.txtSize * ((ct.gridsize.Width * 1.0) / 10.0))) < 4)))
                {
                    g.DrawString(base.text, new Font(base.txtFont, (float)((int)(base.txtSize * ((ct.gridsize.Width * 1.0) / 10.0))), FontStyle.Regular), linePen.Brush, layoutRectangle, format);
                }
            }
        }

        public override Point getPoint(char c)
        {
            return new Point(-1, -1);
        }

        public override bool hasHotPoint(int d)
        {
            return true;
        }

        public override bool hasPoint(Point pt)
        {
            return false;
        }

        public override void onSpaceChar()
        {
            base.direction = (base.direction + base.changeStep) % 2;
            base.sizeDefine = new Size(base.sizeDefineHeight, base.sizeDefineWidth);
            this.resetSize();
        }

        public override void resetSize()
        {
            this.rectReal.Width = base.sizeDefineWidth * 2;
            this.rectReal.Height = base.sizeDefineHeight * 2;
            this.rectReal.Location = new Point(base.pointX * 2, base.pointY * 2);
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("");
            builder.Append(StringUtil.TrimAndPadRight4ASCII(base.text, 1)).Append("文本");
            builder.Append(" 坐标(").Append(base.pointX).Append(',').Append(base.pointY).Append(')');
            return builder.ToString();
        }

        public override string toStringKgl()
        {
            return "";
        }

        public override string toStringXiangshu()
        {
            int num = (base.txtColor.R + (base.txtColor.G << 8)) + (base.txtColor.B << 0x10);
            return string.Concat(new object[] { 
                base.text, ",", base.sharpType, ",", base.subType, ",", (base.lineColor.R + (base.lineColor.G << 8)) + (base.lineColor.B << 0x10), ",", base.direction, ",", base.pointX, ",", base.pointY, ",", base.sizeDefineWidth, ",", 
                base.sizeDefineHeight, ",", base.txtSize, ",", num, ",", base.txtFont, ",", base.isHideTxt ? "1" : "0"
             });
        }

        public override void xuanzhuan180(Point center)
        {
            Point point = new Point(base.pointX + base.sizeDefineWidth, base.pointY + base.sizeDefineHeight);
            Point point2 = new Point(center.X - point.X, center.Y - point.Y);
            base.point = point2;
        }
    }
}

